//
//  Foo.m
//  FooFromScratch
//
//  Created by oisee on 31.01.10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Foo.h"


@implementation Foo

- (IBAction)generation: (id) sender; {
	
	int generated;
	generated = (random() %100)+1;
	NSLog(@"generated = %d", generated);
	[textField setIntValue:generated];
	
}
- (IBAction)seed:(id) sender {
	
	srandom(time(NULL));
	[textField setStringValue:@"Generator seeded"];
}

- (IBAction)selector:(id) sender {
	
	[textField setStringValue:@"selector"];
}
-(void)awakeFromNib {
	NSCalendarDate *now;
	now = [NSCalendarDate calendarDate];
	[textField setObjectValue:now];
	
	
	[tableView registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
	[tableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
    [tableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
}

-(id) init{
	[super init];
	myArray = [[NSMutableArray alloc] initWithCapacity:6];
	//	NSLog([myArray]);
	[myArray addObject:@"one"];
	[myArray addObject:@"two"];
	[myArray addObject:@"three"];
	[myArray addObject:@"four"];
	[myArray addObject:@"five"];
	[myArray addObject:@"six"];
	return self;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tv {
	return [myArray count];
}
- (id)tableView:(NSTableView *)aTableView 
objectValueForTableColumn:(NSTableColumn *)aTableColumn
			row:(NSInteger)rowIndex {
	
	return ([myArray objectAtIndex:rowIndex]);
}

//- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
//{
//    // Copy the row numbers to the pasteboard.
//    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
//    [pboard declareTypes:[NSArray arrayWithObject:MyPrivateTableViewDataType] owner:self];
//    [pboard setData:data forType:MyPrivateTableViewDataType];
//    return YES;
//}

- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
    // Add code here to validate the drop
	
    NSLog(@"validate Drop");
    return NSDragOperationEvery;
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
			  row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
	NSPasteboard* pboard = [info draggingPasteboard];
	//    NSData* rowData = [pboard dataForType:NSFilenamesPboardType];
	//    NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
	//    int dragRow = [rowIndexes firstIndex];
	
	//	NSString *string = [pboard stringForType:NSStringPboardType];
	
//	NSString * string;
	NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];

	for(NSString *s in filenames) {
		NSLog([NSString stringWithFormat:@"s=%@", s]);
		
		[myArray addObject:s];
	}
		
	
	[tableView reloadData];
	
    // Move the specified row to its new location...
}

@end
